<script setup lang="ts">
import { useCorps } from "@/views/corpManagement/corp/utils/hook";
import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Checked from "@iconify-icons/ep/document-checked";
import Look from "@iconify-icons/ep/view";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { ref } from "vue";
const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  isShow,
  onSearch,
  resetForm,
  openDialog,
  handleSizeChange,
  handleCurrentChange,
  deviceDetection,
  handleDelete,
  onFormOneClick,
  onDetail
} = useCorps();
const formRef = ref();
const statusOptions = [
  { value: 0, label: "未审核" },
  { value: 1, label: "审核中" },
  { value: 2, label: "成功启用" },
  { value: 3, label: "审核失败" },
  { value: 4, label: "禁用" }
];
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item label="关键字:">
        <el-input
          v-model="form.keyword"
          class="!w-[180px]"
          clearable
          placeholder="关键字搜索"
        />
      </el-form-item>
      <el-form-item label="状态:">
        <el-select
          v-model="form.status"
          placeholder="请选择"
          clearable
          class="!w-[180px]"
        >
          <el-option
            v-for="(item, index) in statusOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <div
      ref="contentRef"
      :class="['flex', deviceDetection() ? 'flex-wrap' : '']"
    >
      <PureTableBar
        :class="[isShow && !deviceDetection() ? '!w-[60vw]' : 'w-full']"
        style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
        title="企业列表"
        :columns="columns"
        @refresh="onSearch"
      >
        <template #buttons>
          <el-button
            type="primary"
            :icon="useRenderIcon(AddFill)"
            @click="openDialog()"
          >
            添加企业
          </el-button>
        </template>
        <template v-slot="{ size, dynamicColumns }">
          <pure-table
            ref="tableRef"
            align-whole="center"
            showOverflowTooltip
            table-layout="auto"
            :loading="loading"
            :size="size"
            adaptive
            :adaptiveConfig="{ offsetBottom: 108 }"
            :data="dataList"
            :columns="dynamicColumns"
            :pagination="pagination"
            :paginationSmall="size === 'small' ? true : false"
            :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }"
            @page-size-change="handleSizeChange"
            @page-current-change="handleCurrentChange"
          >
            <template #operation="{ row }">
              <!-- <el-popconfirm
                v-if="row.status === 0"
                :title="`是否审核通过?`"
                confirm-button-text="通过"
                cancel-button-text="拒绝"
                cancel-button-type="danger"
                @confirm="confirmStatus(row.corpId)"
                @cancel="refusedStatus(row.corpId)"
              >
                <template #reference>
                  <el-button
                    class="reset-margin"
                    link
                    type="primary"
                    :size="size"
                  >
                    审核
                  </el-button>
                </template>
              </el-popconfirm> -->
              <el-button
                class="reset-margin !outline-none"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(Checked)"
                @click="onFormOneClick(row)"
              >
                审核
              </el-button>
              <el-button
                class="reset-margin !outline-none"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(Look)"
                @click="onDetail(row)"
              >
                详情
              </el-button>
            </template>
          </pure-table>
        </template>
      </PureTableBar>
    </div>
  </div>
</template>

<style scoped lang="scss">
.main-content {
  margin: 10px 10px 0 !important;
}
</style>
